package com.example.blog.config;

import com.example.blog.common.Constants;
import com.example.blog.model.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Home-pc
 * Date: 2024-02-26
 * Time: 14:33
 */
@ResponseBody
@ControllerAdvice
public class ErrorAdvice {
    /**
     * @ExceptionHandler 统一处理方法抛出来的异常,将其抛给Controller
     */
    @ExceptionHandler
    public Result errorHandler(Exception e){
        Result result = new Result();
        result.setErrorMsg("内部错误，请联系管理员");
        result.setCode(Constants.RESULT_FAIL);
        return result;
    }
}
